<template>
	<div>
		<el-dialog :title="$t('action.add')" width="70%" class="icon-dialog" :visible.sync="show" @open="open" :before-close="closeForm" append-to-body>
			<el-form :size="size" ref="form" :model="form" :rules="rules" :label-width="$store.getters.device !== 'mobile'?'16%':'90px'">
 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_name')" prop="name">
							<el-input v-model="form.name" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_name')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_number')" prop="number">
							<el-input v-model="form.number" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_number')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_real_name')" prop="real_name">
							<el-input v-model="form.real_name" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_real_name')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_password')" prop="password">
							<el-input  show-password autoComplete="off" v-model="form.password"  clearable :placeholder="$t('system.pleaseInput',{title:$t('field.User_password')})"/>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_safety_password')" prop="safety_password">
							<el-input  show-password autoComplete="off" v-model="form.safety_password"  clearable :placeholder="$t('system.pleaseInput',{title:$t('field.User_safety_password')})"/>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_phone')" prop="phone">
							<el-input v-model="form.phone" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_phone')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_encrypt_phone')" prop="encrypt_phone">
							<el-input v-model="form.encrypt_phone" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_encrypt_phone')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_md5_phone')" prop="md5_phone">
							<el-input v-model="form.md5_phone" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_md5_phone')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_card')" prop="card">
							<el-input v-model="form.card" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_card')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_code')" prop="code">
							<el-input v-model="form.code" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_code')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_email')" prop="email">
							<el-input v-model="form.email" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_email')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_we_chat')" prop="we_chat">
							<el-input v-model="form.we_chat" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_we_chat')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_alipay')" prop="alipay">
							<el-input v-model="form.alipay" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_alipay')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_qq')" prop="qq">
							<el-input v-model="form.qq" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_qq')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_reid')" prop="reid">
							<el-input v-model="form.reid" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_reid')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_simulate_uid')" prop="simulate_uid">
							<el-input v-model="form.simulate_uid" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_simulate_uid')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_agent')" prop="agent">
							<el-input v-model="form.agent" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_agent')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_staff')" prop="staff">
							<el-input v-model="form.staff" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_staff')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_mother')" prop="mother">
							<el-input v-model="form.mother" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_mother')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_push_team')" prop="push_team">
							<el-input v-model="form.push_team" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_push_team')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_team')" prop="team">
							<el-input v-model="form.team" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_team')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.User_extension_type')" prop="extension_type">
                            <el-select style="width:100%" v-model="form.extension_type" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="推广码" :value="0"></el-option>
                                <el-option key="1"  label="推广链接" :value="1"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.User_type')" prop="type">
                            <el-select style="width:100%" v-model="form.type" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="普通用户" :value="0"></el-option>
                                <el-option key="1"  label="测试用户" :value="1"></el-option>
                                <el-option key="2"  label="机构" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.User_status')" prop="status">
                            <el-select style="width:100%" v-model="form.status" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="禁用" :value="0"></el-option>
                                <el-option key="1"  label="正常" :value="1"></el-option>
                                <el-option key="2"  label="锁定" :value="2"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_photo')" prop="photo">
							<el-input v-model="form.photo" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_photo')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_create_time')" prop="create_time">
							<el-input v-model="form.create_time" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_create_time')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_ip')" prop="ip">
							<el-input v-model="form.ip" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_ip')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_certified')" prop="certified">
							<el-radio-group v-model="form.certified">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="0">否</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				 </el-row>  
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_certified_time')" prop="certified_time">
							<el-date-picker type="date"   v-model="form.certified_time" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.User_certified_time')})"></el-date-picker>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_vip')" prop="vip">
							<el-select style="width:100%" v-model="form.vip" filterable clearable :placeholder="$t('system.pleaseSelect')">
								<el-option v-for="(item,i) in vips" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_bindwechat')" prop="bindwechat">
							<el-input v-model="form.bindwechat" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_bindwechat')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_token')" prop="token">
							<el-input v-model="form.token" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_token')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_update_time')" prop="update_time">
							<el-input v-model="form.update_time" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_update_time')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_last_time')" prop="last_time">
							<el-date-picker type="date"   v-model="form.last_time" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.User_last_time')})"></el-date-picker>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_login_time')" prop="login_time">
							<el-date-picker type="date"   v-model="form.login_time" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.User_login_time')})"></el-date-picker>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_login_ip')" prop="login_ip">
							<el-input v-model="form.login_ip" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_login_ip')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_bank')" prop="bank">
							<el-radio-group v-model="form.bank">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="0">否</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				 </el-row>  
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_activity1')" prop="activity1">
							<el-input v-model="form.activity1" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_activity1')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_caller')" prop="caller">
							<el-select style="width:100%" v-model="form.caller" filterable clearable :placeholder="$t('system.pleaseSelect')">
								<el-option v-for="(item,i) in callers" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_core_set')" prop="core_set">
							<el-select style="width:100%" v-model="form.core_set" filterable clearable :placeholder="$t('system.pleaseSelect')">
								<el-option v-for="(item,i) in core_sets" :key="i" :label="item.key" :value="item.val"></el-option>
							</el-select>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_is_trade_channel_agree')" prop="is_trade_channel_agree">
							<el-radio-group v-model="form.is_trade_channel_agree">
                                <el-radio :label="1">是</el-radio>
                                <el-radio :label="0">否</el-radio>
							</el-radio-group>
						</el-form-item>
					</el-col>
				 </el-row>  
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_app_version')" prop="app_version">
							<el-input v-model="form.app_version" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_app_version')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_peizi_auth')" prop="peizi_auth">
							<el-input v-model="form.peizi_auth" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_peizi_auth')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
				   <el-col :span="24">
                        <el-form-item :label="$t('field.User_certified_synced')" prop="certified_synced">
                            <el-select style="width:100%" v-model="form.certified_synced" :size="size" clearable filterable :placeholder="$t('system.pleaseSelect')">
                                <el-option key="0"  label="未同步" value="0"></el-option>
                                <el-option key="1"  label="已同步" value="1"></el-option>
                                <el-option key="2"  label="同步失败" value="2"></el-option>
                            </el-select>
                        </el-form-item>
                   </el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_remark')" prop="remark">
							<el-input v-model="form.remark" autoComplete="off" clearable  :placeholder="$t('system.pleaseInput',{title:$t('field.User_remark')})">
							</el-input>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_last_token_time')" prop="last_token_time">
							<el-date-picker type="date"   v-model="form.last_token_time" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.User_last_token_time')})"></el-date-picker>
						</el-form-item>
					</el-col>
				 </el-row>
	 				 <el-row >
					<el-col :span="24">
						<el-form-item :label="$t('field.User_token_time')" prop="token_time">
							<el-date-picker type="date"   v-model="form.token_time" clearable :placeholder="$t('system.pleaseInput',{title:$t('field.User_token_time')})"></el-date-picker>
						</el-form-item>
					</el-col>
				 </el-row>
				</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button :size="size" :loading="loading" type="primary" @click="submit" >
					<span v-if="!loading">{{$t('system.confirm')}}</span>
					<span v-else>{{$t('system.submitting')}}</span>
				</el-button>
				<el-button :size="size" @click="closeForm">{{$t('system.cancel')}}</el-button>
			</div>
		</el-dialog>
	</div>
</template>
<script>
import { add, getFieldList } from '@/api/app/user'



export default {
	name:'useradd',
	components: {
	   	   
	},
	props: {
		show: {
			type: Boolean,
			default: false
		},
		size: {
			type: String,
			default: 'small'
		},
		querys:{
			type:Object,
		},
	},
	data(){
		return {
		    dialog:{
			},
			
			form: {
			   name:'',
			   number:'',
			   real_name:'',
			   password:'',
			   safety_password:'',
			   phone:'',
			   encrypt_phone:'',
			   md5_phone:'',
			   card:'',
			   code:'',
			   email:'',
			   we_chat:'',
			   alipay:'',
			   qq:'',
			   reid:'',
			   simulate_uid:'',
			   agent:'',
			   staff:'',
			   mother:'',
			   push_team:'',
			   team:'',
			   extension_type:0,
			   type:0,
			   status:1,
			   photo:'',
			   create_time:'',
			   ip:'',
			   certified:0,
			   certified_time:'',
			   vip:'',
			   bindwechat:'',
			   token:'',
			   update_time:'',
			   last_time:'',
			   login_time:'',
			   login_ip:'',
			   bank:0,
			   activity1:'',
			   caller:'',
			   core_set:1,
			   is_trade_channel_agree:1,
			   app_version:'',
			   peizi_auth:'',
			   certified_synced:'1',
			   remark:'',
			   last_token_time:'',
			   token_time:'',
			},
			vips:[],
			callers:[],
			core_sets:[],
		    initial:{},   
			loading:false,
			rules: {
			}
		}
	},
	watch:{
		show(val){
			if(val){
				getFieldList().then(res => {
					if(res.status == 200){
						this.vips = res.data.vips
						this.callers = res.data.callers
						this.core_sets = res.data.core_sets
					}
				})
			}
		}
	},
	methods: {
		open(){
		  if(this.querys){
		  }
		},
		submit(){
			this.$refs['form'].validate(valid => {
				if(valid) {
					this.loading = true
					add(this.form).then(res => {
						if(res.status == 200){
							this.$message({message: this.$t('system.success'), type: 'success'})
							this.$emit('refresh_list')
							this.closeForm()
						}
					}).catch(()=>{
						this.loading = false
					})
				}
			})
		},
		closeForm(){
			this.$emit('update:show', false)
			this.loading = false
			if (this.$refs['form']!==undefined) {
				this.$refs['form'].resetFields()
			}
		},
	}
}
</script>
<style scoped lang="scss">
@import '@/assets/scss/common.scss'
</style>
